package eworldpacs.ui;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ElementViewAdapter extends ArrayAdapter<String> {
   
   Context context;
   String[] values;
   public static final int TAG_INDEX = 1;
   public static final int NAME_INDEX = 3;
   public static final int VR_INDEX = 5;
   public static final int LENGTH_INDEX = 7;
   public static final int VALUE_INDEX = 9;
   
   public ElementViewAdapter(Context context, int elementViewResourceId, String[] values) {
       super(context, elementViewResourceId, values);
       this.context = context;
       this.values = values;
     }

     @Override
     public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;

        if(row == null){
           row = new TextView(parent.getContext());
        }

        TextView label=(TextView)row;
        label.setTextColor(Color.WHITE);
        label.setTextSize(15);
        label.setText(values[position]);
        label.setMaxLines(1);
        label.setEllipsize(TextUtils.TruncateAt.END);
        label.setBackgroundColor(Color.TRANSPARENT);
        return row;
     }
     
     @Override
     public boolean isEnabled(int position){
        return (position % 2  == 0) ? false : true;
     }
     
     public void setValueAtIndex(int index, String value){
        values[index] = value;
        this.notifyDataSetChanged();
     }
     
     public void setEmptyElementValues(){
        this.setValueAtIndex(TAG_INDEX, "");
        this.setValueAtIndex(NAME_INDEX, "");
        this.setValueAtIndex(VR_INDEX, "");
        this.setValueAtIndex(LENGTH_INDEX, "");
        this.setValueAtIndex(VALUE_INDEX, "");
     }
}
